package models

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

// 用户消费信息
type UserConsumptionInformation struct {
	Id                        uint64         `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId                    int32          `gorm:"column:user_id;type:int;default:NULL;" json:"user_id"`
	PayNo                     int32          `gorm:"column:pay_no;type:int;comment:支付单号;default:NULL;" json:"pay_no"`                                                      // 支付单号
	Event                     string         `gorm:"column:event;type:varchar(255);comment:事件;default:NULL;" json:"event"`                                                 // 事件
	PriceTime                 time.Time      `gorm:"column:price_time;type:datetime;comment:消费时间;default:NULL;" json:"price_time"`                                         // 消费时间
	OrderNo                   string         `gorm:"column:order_no;type:varchar(255);comment:订单编号;default:NULL;" json:"order_no"`                                         // 订单编号
	GiftAmount                string         `gorm:"column:gift_amount;type:varchar(255);comment:赠送金额;default:NULL;" json:"gift_amount"`                                   // 赠送金额
	RechargeAmountPrincipal   string         `gorm:"column:recharge_amount_principal;type:varchar(255);comment:充值金额-本金（元）;default:NULL;" json:"recharge_amount_principal"` // 充值金额-本金（元）
	TotalRechargeAmount       int32          `gorm:"column:total_recharge_amount;type:int;comment:总充值金额;default:NULL;" json:"total_recharge_amount"`                       // 总充值金额
	RefundAmount              int32          `gorm:"column:refund_amount;type:int;comment:退款金额;default:NULL;" json:"refund_amount"`                                        // 退款金额
	TotalOrderPrice           float64        `gorm:"column:total_order_price;type:decimal(10, 2);comment:总订单支付金额;default:NULL;" json:"total_order_price"`                  // 总订单支付金额
	MonthlyOrderPaymentAmount int32          `gorm:"column:monthly_order_payment_amount;type:int;comment:本月订单支付金额 ;default:NULL;" json:"monthly_order_payment_amount"`     // 本月订单支付金额
	CreatedAt                 time.Time      `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt                 time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt                 gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *UserConsumptionInformation) TableName() string {
	return "user_consumption_information"
}

func (u *UserConsumptionInformation) Create() error {
	return config.DB.Create(u).Error
}

func (u *UserConsumptionInformation) Detail() error {
	return config.DB.Where("id = ?", u.Id).Find(&u).Error
}

func (u *UserConsumptionInformation) GetUserConsumptionInformationById() error {
	return config.DB.Where("user_id = ?", u.UserId).Find(&u).Error
}
